﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Microsoft.Practices.Unity;
using MvcWiki.DependencyInjection.Unity;

namespace MvcWiki.Web.Prototype.MVC2P1.Wiki.Prototyping
{
    public static class Injections
    {
        public static void InjectDefault(IUnityContainer container)
        {
            container.RegisterType<MvcWiki.Repository.IUnitOfWork, MvcWiki.Repository.UnitOfWork>(
                new HttpContextLifetimeManager<MvcWiki.Repository.IUnitOfWork>());

            container.RegisterType<MvcWiki.Markup.IWikiMarkupProvider, MvcWiki.Web.Prototype.MVC2P1.Wiki.Prototyping.WikiMarkupPrototypeProvider>(
                new HttpContextLifetimeManager<MvcWiki.Markup.IWikiMarkupProvider>());

            container.RegisterType<MvcWiki.Repository.IWikiRepositoryFactory, MvcWiki.Repository.FileSystem.WikiFileSystemRepositoryFactory>(
                new HttpContextLifetimeManager<MvcWiki.Repository.IWikiRepositoryFactory>())
                    .Configure<InjectedMembers>()
                    .ConfigureInjectionFor<MvcWiki.Repository.FileSystem.WikiFileSystemRepositoryFactory>(
                        new InjectionConstructor(
                            new ResolvedParameter<MvcWiki.Markup.IWikiMarkupProvider>(),
                            new ResolvedParameter<MvcWiki.Repository.IUnitOfWork>(),
                            HttpContext.Current.Server.MapPath("~/App_Data")
                        )
                    );

            container.RegisterType<MvcWiki.User.IWikiUserProvider, MvcWiki.User.WikiUserProviderBase>(
                new HttpContextLifetimeManager<MvcWiki.User.IWikiUserProvider>());

            container.RegisterType<MvcWiki.Service.IWikiPageService, MvcWiki.Service.WikiPageService>
                (new HttpContextLifetimeManager<MvcWiki.Service.IWikiPageService>());

            container.RegisterType<MvcWiki.Service.IWikiNamespaceService, MvcWiki.Service.WikiNamespaceService>
                (new HttpContextLifetimeManager<MvcWiki.Service.IWikiNamespaceService>());
        }
    }
}
